//======================================================================
//
//	HDRSample
//
//		by MJP
//		09/20/08
//
//======================================================================
//
//	File:		Skybox.fx
//
//	Desc:		Renders a skybox using a cube map.
//
//======================================================================

#include "LogLuv.fxh"

float4x4  g_matView;
float4x4  g_matProj;

float g_fBrightness;

texture SkyboxTexture;
samplerCUBE SkyboxSampler = sampler_state
{
    Texture = <SkyboxTexture>;
    MinFilter = linear;
    MagFilter = linear;
    MipFilter = linear;
    AddressU = Clamp;
    AddressV = Clamp;
    AddressW = Clamp;
    MaxAnisotropy = 1;
};

struct VS_INPUT
{
	float4 position : POSITION0;
    float3 texel0 : TEXCOORD0;
};

struct VS_OUTPUT
{
    float4 position : POSITION0;
    float3 texel0 : TEXCOORD0;
};



void SkyboxVS(	in float3 in_vPositionOS	: POSITION,
				in float3 in_vTexCoord		: TEXCOORD0,
				out float4 out_vPositionCS	: POSITION,
				out float3 out_vTexCoord	: TEXCOORD0 )
{
	float4 vPositionVS = float4(mul(in_vPositionOS * 2.0f, (float3x3)g_matView), 1.0f);
	out_vPositionCS = mul(vPositionVS, g_matProj);
    out_vTexCoord = in_vTexCoord;
}

float4 SkyboxPS( in float3 in_vTexCoord	: TEXCOORD0,
				 uniform bool bEncodeLogLuv	)	: COLOR0
{	
	float4 vColor = texCUBE(SkyboxSampler, in_vTexCoord) * g_fBrightness;
	if (bEncodeLogLuv)
		vColor = LogLuvEncode(vColor.rgb);	
	return vColor;		
}

technique Skybox
{
    pass p0
    {
	/*
		ZEnable = false;
		ZWriteEnable = false;
		AlphaBlendEnable = false;
		CullMode = none;
		AlphaTestEnable = false;
		StencilEnable = false;
    */
        VertexShader = compile vs_2_0 SkyboxVS();
        PixelShader = compile ps_2_0 SkyboxPS(false);
    }
}

technique SkyboxEncode
{
    pass p0
    {
	/*
		ZEnable = false;
		ZWriteEnable = false;
		AlphaBlendEnable = false;
		CullMode = none;
		AlphaTestEnable = false;
		StencilEnable = false;	
    */
        VertexShader = compile vs_2_0 SkyboxVS();
        PixelShader = compile ps_2_0 SkyboxPS(true);
    }
}
